package com.yy.permissions_general.security.handler;


import com.yy.permissions_general.utils.FastJsonUtils;
import com.yy.permissions_general.utils.ResultUtil;
import com.yy.permissions_general.utils.ServletUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: TODO 退出登录
 * @Author: YangYI
 * @Date: 2021/11/1
**/
@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        //修改编码格式
        SecurityContextHolder.clearContext();
        ServletUtil.write(FastJsonUtils.toString(ResultUtil.success("退出成功~")));
    }
}
